package com.ruoyi.common.flowable.execution;

import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.engine.impl.persistence.entity.HistoricProcessInstanceEntityImpl;
import org.flowable.engine.task.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

@Component("BatchBusinessListener")
public class BatchBusinessListener extends MyFlowableEventListener {
/*    @Autowired
    private BatchBusinessServiceImpl batchBusinessService;*/

    @Override
    public void onEvent(FlowableEvent event) {
        if (event.getType().equals(FlowableEngineEventType.HISTORIC_PROCESS_INSTANCE_ENDED)) {//流程终止
            HistoricProcessInstanceEntityImpl taskEntity = (HistoricProcessInstanceEntityImpl) ((org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl) event).getEntity();
            List<Comment> commentList = taskService.getProcessInstanceComments(taskEntity.getProcessInstanceId());
            //FlowTaskDto taskDto = actHiProcinstMapper.getByProcInsId(taskEntity.getProcessInstanceId());
            String id = getId(taskEntity);
           /* if (commentList.isEmpty()) {
                batchBusinessService.doAuditPassFinish(id);
            } else {
                if (commentList.get(0).getType().equals(FlowComment.STOP.getCode())) {
                    batchBusinessService.doAuditRejectFinish(id);
                } else if (commentList.get(0).getType().equals(FlowComment.NORMAL.getCode())) {
                    batchBusinessService.doAuditPassFinish(id);
                }
            }*/

        }
    }

    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return null;
    }

}
